<%-- 
    Document   : index
    Created on : 12.04.2011, 15:53:28
    Author     : Михаил
--%>

<%@page import="unc.pds.auth.SecurityST"%>
<%@page import="unc.pds.auth.IPDSSecurity"%>
<%@page import="unc.pds.auth.SecurityBRemoteHome"%>
<%@page import="unc.pds.auth.SecurityBRemote"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="unc.pds.service.ServiceBeanRemoteHome"%>
<%@page import="unc.pds.service.ServiceBeanRemote"%>
<%@page import="unc.pds.model.UserRemote"%>
<%@page import="unc.pds.facets.Facet"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="unc.pds.facets.FacetManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%
    if ((request.getParameter("id")==null)&&(request.getParameter("view")==null)) {
        response.sendRedirect("login.jsp");
    } else {
        ServiceBeanRemote service = ((ServiceBeanRemoteHome)(new InitialContext()).lookup("ejb/ServiceBean")).create((Long)session.getAttribute("sid"));
        IPDSSecurity security = SecurityST.getSecurity((Long)session.getAttribute("sid"));
        ArrayList facetList = FacetManager.getFacetList(request.getParameter("id"), request.getParameter("view"), service, security);
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="resources/stylesheet.css" type="text/css"/>
        <script src="resources/validate.js"></script>
        <title>Мой дневник</title>
    </head>
    <body>
    <div id="container">
        <div id="header">
            Вы вошли как <a href ="index.jsp?id=<%= service.getUser().getKey() %>&view=posts">
                <%= service.getUser().getNickname() %>
            </a><br/>
            <a href = "logout-processor.jsp">Выход</a>
            <form action="find.jsp" method="get" onsubmit="return validateEmpty('string');">
                <input type="text" name="string" id="string"/>
                <input type="submit"value="Искать"/>
            </form>
        </div>
        <div id="main-facets">
            <%
                Iterator facets = facetList.iterator();
                boolean sideAru = false;
                while (facets.hasNext()) {
                    Facet current = (Facet)facets.next();
                    if (!current.isSide()) {
            %>
            <div id="facet"><%= current.draw() %></div>
            <%
                    }
                }
            %>
        </div>
        <div id="side-facets">
            <%
                facets = facetList.iterator();
                while (facets.hasNext()) {
                    Facet current = (Facet)facets.next();
                    if (current.isSide()) {
            %>
            <div id="facet"><%= current.draw() %></div>
            <%
                    }
                }
            %>
        </div>
    </div>
    </body>
</html>
<%
    }
%>
